/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package exception;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *
 * @author carlos
 */
public class DuplicateConstraintException extends Exception {

    private String name;
    private String value;

    public DuplicateConstraintException(String name, String value) {
        this.name = name;
        this.value = value;
    }

    public DuplicateConstraintException(String name, Date value) {
        SimpleDateFormat dateToStr = new SimpleDateFormat("dd/MM/yyyy");
        this.name = name;
        this.value = dateToStr.format(value);
    }

    public DuplicateConstraintException(String name, Date value, String strValue) {
        SimpleDateFormat dateToStr = new SimpleDateFormat("dd/MM/yyyy");
        this.name = name;
        this.value = dateToStr.format(value) + " " + strValue;
    }

    @Override
    public String getMessage() {
        return ("Já existe um registro cadastrado com o campo '" + name.toUpperCase() + "' com valor '" + value + "'.");
    }
}
